<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         * 2.作为对象的方法去调用
         * 3.在箭头函数中this指向
        */
        var name = "window"
        var obj = {
            name: "javascript",
            sayName() {
                console.log(this.name);      //javascript
            },
            wait() {
                console.log(this.name);      //javascript
                setTimeout(function () {
                    console.log(this.name);  //window
                })
            },
            delay() {
                setTimeout(() => {
                    console.log(this.name);  //javascript
                })
            },
            layOut() {
                setTimeout(function () {
                    console.log(this.name);  //javascript
                }.bind(this));
            },
            print() {
                var that = this;
                setTimeout(function () {
                    console.log(this.name);  //javascript
                }.bind(that));
            }
        }
        obj.sayName();
        obj.wait();
        obj.delay();
        obj.layOut();
        obj.print();
    </script>
</body>

</html>